﻿using IdentityServer4;
using IdentityServer4.Models;
using IdentityServer4.Test;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace FarFiles
{
    public class IdentityServerConfig
    {
        public static IEnumerable<ApiResource> GetApiResources()
        {
            List<ApiResource> apis = new List<ApiResource>();
            apis.Add(new ApiResource("sendEmail", "apiEmail显示名字")
            {
                Scopes = { "sendEmail" },
            });

            apis.Add(new ApiResource()
            {
                Name = "sendMessage",
                DisplayName = "apiMessage",
                Scopes = { "sendMessage" },
            });

            apis.Add(new ApiResource()
            {
                Name = "iosApiResource",
                DisplayName = "苹果访问接口—密码访问方式",
                Scopes = { "iosApiResource" },
            });

            apis.Add(new ApiResource
            {
                Name = "api1",
                DisplayName = "15节 oauth2 + oidc ",
                Scopes = { "api1Resource" }
            });

            return apis;
        }

        public static IEnumerable<Client> GetClients()
        {
            List<Client> cLs = new List<Client>();
            cLs.Add(new Client
            {
                ClientId = "mvc",
                // 密码模式  客户端模式 隐士模式  授权码模式
                AllowedGrantTypes = GrantTypes.Implicit, // 隐士模式
                ClientSecrets = { new Secret("12345".Sha256()) },
                AllowedScopes = {
                    "api1",
                    IdentityServerConstants.StandardScopes.OpenId,
                 IdentityServerConstants.StandardScopes.Profile
                },
                AllowOfflineAccess = true,
                //处理认证登录地址
                //RedirectUris = { "http://localhost:5100/sigin-oidc" },
                RedirectUris = { "https://localhost:5100/Identity/Account/Login" },
                PostLogoutRedirectUris = { "http://localhost:5100/signout-callback-oidc" },

                RequireConsent = false,
            });


            //cLs.Add(new Client
            //{
            //    ClientId = "ios",
            //    AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
            //    ClientSecrets = { new Secret("123".Sha256()) },
            //    AllowedScopes = { "iosApiResource", IdentityServerConstants.StandardScopes.OpenId,
            //     IdentityServerConstants.StandardScopes.Profile},
            //    AllowOfflineAccess = true,
            //    //如果设备false  则请求端可以不带秘钥
            //    RequireClientSecret = false,
            //});

            return cLs;
        }

        public static IEnumerable<ApiScope> ApiScopes =>
        new ApiScope[]
        {
            new ApiScope("sendEmail"),
            new ApiScope("sendMessage"),
            new ApiScope("iosApiResource"),
            new ApiScope("api1Resource"),
        };

        public static IEnumerable<IdentityResource> GetIdentityResource()
        {

            return new List<IdentityResource>()
            {
                new IdentityResources.OpenId(),
                new IdentityResources.Profile(),
                new IdentityResources.Email(),
            };
        }

        public static List<TestUser> TestUsers()
        {
            return new List<TestUser>
            {
               new TestUser
               {
                   SubjectId="1000",
                   Username="wz",
                   Password="wz123",

               }
             };
        }
    }
}
